package com.weed.pattern.filter2;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

/**
 * 过滤器
 *
 * @author zhong.wang
 * @date 2024/10/24
 */
public interface Filter<C extends FilterContext> {
    /**
     * 执行过滤
     * @param filterContext 过滤内容
     * @return
     */
    Boolean filter(C filterContext);

    /**
     * 组装过滤器
     * @param filters
     * @return
     */
    static Filter composite(Iterable<Filter> filters) {
        return composite(
                StreamSupport.stream(filters.spliterator(), false)
                        .collect(Collectors.toList())
        );
    }

    /**
     * 组装过滤器
     * @param filters
     * @return
     */
    static Filter composite(List<Filter> filters) {
        return new CompositeFilter(Collections.unmodifiableList(filters));
    }
}
